package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Repository;

import com.ibeifeng.crm.bean.Record;
import com.ibeifeng.crm.dao.RecordDao;
@Repository
public class RecordDaoImpl implements RecordDao {
	@Resource
	SqlSessionFactory factory;

	@Override
	public boolean delete(List<Integer> list) {
		// TODO Auto-generated method stub
		int i = factory.openSession().delete("com.ibeifeng.crm.dao.RecordDao.delete",list);
		if(i>0){
			System.out.println("删除成功！");
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean update(Record rd) {
		// TODO Auto-generated method stub
		int i = factory.openSession().update("com.ibeifeng.crm.dao.RecordDao.update",rd);
		if(i>0){
			System.out.println("更新成功！");
			return true;
		}else{
			return false;
		}
	}
	Map map = new HashMap();
	@Override
	public List<Record> mquery(int pg, int pgSize,String keyWord) {
		
		int start=(pg-1)*pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		map.put("keyWord", keyWord);
		List<Record> list =factory.openSession().selectList("com.ibeifeng.crm.dao.RecordDao.mquery",map);
		return list;
	}

	@Override
	public boolean add(Record rd) {
		// TODO Auto-generated method stub
		int i = factory.openSession().insert("com.ibeifeng.crm.dao.RecordDao.add",rd);
		if(i>0){
			System.out.println("添加成功！");
			return true;
		}else{
			return false;
		}
	}
	@Override
	public int getAllcount() {
		int i=factory.openSession().selectOne("com.ibeifeng.crm.dao.RecordDao.getAllCount", map);
		return i;
	}

}
